package br.com.eventime.component;

import java.util.List;

import javax.faces.model.ListDataModel;

import org.primefaces.model.SelectableDataModel;

public class DataModelList<E extends BaseEntity<?>> extends ListDataModel<E> implements SelectableDataModel<E> {

	public DataModelList(List<E> list){
		super(list);
	}
	
	public DataModelList(){
		super();
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public E getRowData(String arg0) {
		
		List<E> list = (List<E>) getWrappedData();
		
		if(list == null ) return null;
		if(arg0 == null ) return null;
		if(arg0.length() <= 0 ) return null;
		if(arg0.equals("null") ) return null;
		
		for (E e : list){
			if(e.getIdentificador().equals(Integer.parseInt(arg0))){
				return e;
			}
		}
		
		return null;
		
	}

	@Override
	public Object getRowKey(E arg0) {
		return arg0.getIdentificador();
	}
	
	
	

}
